package com.etrans.web.gps.business.report.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Service;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.report.domain.NightDriving2To5VO;
import com.etrans.web.gps.common.MGTemplete;

/**
 * @author 
 *
 */
@Service
public class NightDriving2To5Service extends BaseService {

	/**
	 * 查询登录用户权限下的所有业户
	 * @return  业户信息列表
	 */
	public List<HashMap<String,Object>> queryEnterAndPlatByRole(int areaId){
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("FullID", String.format("%08d",areaId));
		return  this.selectList("tourismViolation.queryEnterAndPlatByRole",param);
	}
	
	/**
	 * 查询登录用户权限下的所有业户的ID
	 * @return  业户信息列表
	 */
	public List<Integer> queryEnterIdListByRole(int areaId){
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("FullID", String.format("%08d",areaId));
		return  this.selectList("tourismViolation.queryEnterIdListByRole",param);
	}
	
	
	/**
	 * 根据业户查询
	 * @return  该业户下的所有夜行（2-5）的车辆数
	 */
	public Integer queryNightDriCountByEnt(String enterpriseName, Date startTime, Date endTime) {
		//查询条件
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_Time = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_alarmCount = new HashMap<String, Object>();
		whereMap_Time.put("$gte", startTime);	//大于
		whereMap_Time.put("$lte", endTime);		//小于
		whereMap.put("analyse_date", whereMap_Time);
		whereMap.put("enterprise_name", enterpriseName);
		whereMap_alarmCount.put("$gte", 1);
		whereMap.put("prohibit_driving_count", whereMap_alarmCount);
//		whereMap_alarmCount.put("$gt", 0);
//		whereMap.put("mileage_2_5", whereMap_alarmCount);
		Long count = MGTemplete.findCount("egov", "vehicle_swap",whereMap);
		return count.intValue();
	}
	
	/**
	 * 根据时间按照业户名进行分组查询
	 * 
	 */
	public List<Object> queryNightDrivingCount(Date startTime, Date endTime) {
		// 查询条件
		HashMap<String,Object> sortMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_Time = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_alarmCount = new HashMap<String, Object>();
		whereMap_Time.put("$gte", startTime);	//大于
		whereMap_Time.put("$lte", endTime);		//小于
		whereMap.put("analyse_date", whereMap_Time);
		whereMap_alarmCount.put("$gte", 1);
		whereMap.put("prohibit_driving_count", whereMap_alarmCount);
//		whereMap_alarmCount.put("$gt", 0);
//		whereMap.put("mileage_2_5", whereMap_alarmCount);
		sortMap.put("count", -1);
		return MGTemplete.groupBy("egov", "vehicle_swap", whereMap, "enterprise_name", sortMap, 0);
	}

	/**
	 * 根据时间和车牌号进行单车查询
	 * 
	 */
	public List<NightDriving2To5VO> getResultTableByNo(String vehicle_no, Date startTime, Date endTime,int page, int pageSize) {
		// 查询条件
		HashMap<String,Object> sortMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_Time = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_alarmCount = new HashMap<String, Object>();
		whereMap_Time.put("$gte", startTime);	//大于
		whereMap_Time.put("$lte", endTime);		//小于
		whereMap.put("analyse_date", whereMap_Time);
		whereMap_alarmCount.put("$gte", 1);
		whereMap.put("prohibit_driving_count", whereMap_alarmCount);
//		whereMap_alarmCount.put("$gt", 0);
//		whereMap.put("mileage_2_5", whereMap_alarmCount);
		whereMap.put("vehicle_no", vehicle_no);
		sortMap.put("analyse_date", -1);
		return MGTemplete.find("egov", "vehicle_swap", whereMap, sortMap ,page,pageSize,NightDriving2To5VO.class,true);
	}

	/**
	 * 根据时间和业户名进行分页查询
	 * 
	 */
	public List<NightDriving2To5VO> getResultTableByByEnt(String enterpriseName, Date startTime, Date endTime,
			Integer page, Integer pageSize) {
		// 查询条件
		HashMap<String,Object> sortMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_Time = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_alarmCount = new HashMap<String, Object>();
		whereMap_Time.put("$gte", startTime);	//大于
		whereMap_Time.put("$lte", endTime);		//小于
		whereMap.put("analyse_date", whereMap_Time);
		whereMap_alarmCount.put("$gte", 1);
		whereMap.put("prohibit_driving_count", whereMap_alarmCount);
//		whereMap_alarmCount.put("$gt", 0);
//		whereMap.put("mileage_2_5", whereMap_alarmCount);
		whereMap.put("enterprise_name", enterpriseName);
		sortMap.put("analyse_date", -1);
		return MGTemplete.find("egov", "vehicle_swap", whereMap, sortMap ,page,pageSize,NightDriving2To5VO.class,true);
	}

	/**
	 * 根据时间查询全部2点到5点的行车数量
	 * 
	 */
	public Integer queryNightAllCountByRole(List<Integer> entIdList, Date startTime, Date endTime) {
		//查询条件
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_Time = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_alarmCount = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_ent = new HashMap<String, Object>();
		whereMap_Time.put("$gte", startTime);	//大于
		whereMap_Time.put("$lte", endTime);		//小于
		whereMap.put("analyse_date", whereMap_Time);
		whereMap_ent.put("$in", entIdList);
		whereMap.put("enterprise_id", whereMap_ent);
		whereMap_alarmCount.put("$gte", 1);
		whereMap.put("prohibit_driving_count", whereMap_alarmCount);
//		whereMap_alarmCount.put("$gt", 0);
//		whereMap.put("mileage_2_5", whereMap_alarmCount);
		Long count = MGTemplete.findCount("egov", "vehicle_swap",whereMap);
		return count.intValue();
	}
	
	/**
	 * 根据时间查询全部2点到5点的行车信息
	 * 
	 */
	public List<NightDriving2To5VO> getAllResultTableByByRole(List<Integer> entIdList, Date startTime, Date endTime,
			Integer page, Integer pageSize) {
		// 查询条件
		HashMap<String,Object> sortMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_Time = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_alarmCount = new HashMap<String, Object>();
		HashMap<String,Object> whereMap_ent = new HashMap<String, Object>();
		whereMap_Time.put("$gte", startTime);	//大于
		whereMap_Time.put("$lte", endTime);		//小于
		whereMap.put("analyse_date", whereMap_Time);
		whereMap_alarmCount.put("$gte", 1);
		whereMap.put("prohibit_driving_count", whereMap_alarmCount);
//		whereMap_alarmCount.put("$gt", 0);
//		whereMap.put("mileage_2_5", whereMap_alarmCount);
		whereMap_ent.put("$in", entIdList);
		whereMap.put("enterprise_id", whereMap_ent);		
		sortMap.put("analyse_date", -1);
		return MGTemplete.find("egov", "vehicle_swap", whereMap, sortMap ,page,pageSize,NightDriving2To5VO.class,true);
	}

}
